# coding:utf-8
# filename: yangsy.py
# author by: Face

import requests
import json
import warnings

# 去除警告信息
warnings.filterwarnings('ignore')

# 登录接口：
url = 'https://testpassport.rabbitpre.com/api/sso/login'
s = {"account": "18883552113", "password": "abc123456", "fromType": "pc"}
r = requests.post(url, json=s)
cookies = r.cookies
print(r.text)
if  r.json().get('errorCode') != 'SUCCESS':
    raise ValueError('登录失败')

# 获取user接口：
def user():
    try:
        api_url = 'https://bws.test.rabbitpre.com/api/user'
        req = requests.get(api_url, cookies=cookies)
        text = req.text
        # 获取orgId和userId:
        resp = json.loads(text)
        orgid = resp['data']['userOrgInfo']['orgId']
        userid = resp['data']['userId']
    except RuntimeError as e:
        print(e)
    except ValueError as e:
        print(e)
    else:
        print('userId:', userid)
        print('orgId:', orgid)
user()
